package com.owen.springboot.smartparkingms.common.util;

import com.owen.springboot.smartparkingms.module.app.entity.Car;
import org.apache.tomcat.util.http.fileupload.FileUtils;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 日期处理
 */
public class DateUtils {


	/**
	 * 时间格式(yyyy-MM-dd)
	 */
	public final static String DATE_PATTERN = "yyyy-MM-dd";

	/**
	 * 时间格式(yyyy-MM-dd HH:mm:ss)
	 */
	public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";

	public static String format(Date date) {
		return format(date, DATE_PATTERN);
	}

	public static String format(Date date, String pattern) {
		if (date != null) {
			SimpleDateFormat df = new SimpleDateFormat(pattern);
			return df.format(date);
		}
		return null;
	}

	public static String format(Timestamp date, String pattern) {
		if (date != null) {
			SimpleDateFormat df = new SimpleDateFormat(pattern);
			return df.format(date);
		}
		return null;
	}

	public static Date format(String str, String pattern) {
		if (str != null) {
			SimpleDateFormat df = new SimpleDateFormat(pattern);
			try {
				return df.parse(str);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	/**
	 * 获取当前日期
	 *
	 * @return
	 */

	public static String GMTformat(String datdString) {
		datdString = datdString.replace("GMT", "").replaceAll("\\(.*\\)", "");
		//将字符串转化为date类型，格式2016-10-12
		SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss z", Locale.ENGLISH);
		Date dateTrans = null;
		try {
			dateTrans = format.parse(datdString);
			return new SimpleDateFormat(DATE_TIME_PATTERN).format(dateTrans);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return datdString;

	}

	public static Timestamp getTimestamp() {
		return new Timestamp(System.currentTimeMillis());
	}

	public static String getTime() {
		return format(new Timestamp(System.currentTimeMillis()), DATE_TIME_PATTERN);
	}

	public static void main(String[] args) {
		System.out.println(DateUtils.GMTformat("Tue Mar 01 2022 00:00:00 GMT+0800 (中国标准时间)"));
		System.out.println(ZonedDateTime.now());
	}
}